package com.lzxuni.controller;

import com.lzxuni.po.QxDataCostom;
import com.lzxuni.service.SheBeiService;
import com.lzxuni.utils.MethodUtil;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Iterator;
import java.util.List;


@Controller
@RequestMapping("/nydsjjk")
public class NydsjjkController {

	@Autowired
	private SheBeiService sheBeiService;


	// 接口数据
	@RequestMapping("/listDo.html")
	public void listDo( HttpServletRequest request, HttpServletResponse response) throws Exception {


		String userkey = request.getParameter("userkey");
		String pagenum = request.getParameter("pagenum");

		//System.out.println("userkey----------" + userkey);

		String tableName = "tbl_" + userkey;

		QxDataCostom demo =new QxDataCostom();
		demo.setPagenum((Integer.parseInt(pagenum)-1)*10);
		demo.setTablename(tableName);

		List<QxDataCostom> list=sheBeiService.findqxsjlist(demo);


		// 返回json数组分页
		JSONObject jsonObject = new JSONObject();
		JSONArray array = new JSONArray();

		for (Iterator<QxDataCostom> iterator = list.iterator(); iterator.hasNext(); ) {
			JSONObject jsonObject1 = new JSONObject();
			QxDataCostom qxData = iterator.next();

			jsonObject1.put("id", qxData.getId());
			jsonObject1.put("userkey", qxData.getUserkey());
			jsonObject1.put("createTime", MethodUtil.formatDate(0, qxData.getCreateTime()));
			jsonObject1.put("kqwd", qxData.getKqwd());
			jsonObject1.put("kqsd", qxData.getKqsd());
			jsonObject1.put("gz", qxData.getGz());
			jsonObject1.put("trwd", qxData.getTrwd());
			jsonObject1.put("trsd", qxData.getTrsd());
			jsonObject1.put("fs", qxData.getFs());
			jsonObject1.put("fx", qxData.getFx());
			jsonObject1.put("eyht", qxData.getEyht());
			jsonObject1.put("yl", qxData.getYl());

			array.add(jsonObject1);
		}
		jsonObject.put("total", "10");
		jsonObject.put("pagenum", pagenum);
		jsonObject.put("rows", array);

		// 输出
		MethodUtil.writer(response, jsonObject.toString());


	}



	// 接口数据
	@RequestMapping("/listone.html")
	public void listone( HttpServletRequest request, HttpServletResponse response) throws Exception {


		String userkey = request.getParameter("userkey");

		//System.out.println("userkey----------" + userkey);

		String tableName = "tbl_" + userkey;

		QxDataCostom demo = new QxDataCostom();
		demo.setTablename(tableName);

		List<QxDataCostom> list = sheBeiService.findqxsjone(demo);

		QxDataCostom qxData=list.get(0);

		JSONObject jsonObject = new JSONObject();

		jsonObject.put("id", qxData.getId());
		jsonObject.put("userkey", qxData.getUserkey());
		jsonObject.put("createTime", MethodUtil.formatDate(0, qxData.getCreateTime()));
		jsonObject.put("kqwd", qxData.getKqwd());
		jsonObject.put("kqsd", qxData.getKqsd());
		jsonObject.put("gz", qxData.getGz());
		jsonObject.put("trwd", qxData.getTrwd());
		jsonObject.put("trsd", qxData.getTrsd());
		jsonObject.put("fs", qxData.getFs());
		jsonObject.put("fx", qxData.getFx());
		jsonObject.put("eyht", qxData.getEyht());
		jsonObject.put("yl", qxData.getYl());

		// 输出
		MethodUtil.writer(response, jsonObject.toString());

	}


}